/**
 * @author F.biz - http://www.fbiz.com.br/
 */
/**
 * Classe estática para chamar marcações do Google Analytics
 * @author Nicholas Almeida
 * @since 19:18 13/8/2009
 * @see	para testar em localhost, colocar pageTracker._setDomainName("none"); LOGO APÓS a crição da chamada do analytics ANTES do
 */
var Analytics = {
	
	/**
	 * Private
	 */
	_timeout: 250,
	_pageTracker: 'pageTracker',
	
	/**
	 * Atribui valor para _pageTracker
	 */
	setTracker: function(trackerFunction) {
		this._pageTracker = trackerFunction;
	},
	
	/**
	 * Retorna a pageTracker usada
	 */
	getTracker: function() {
		return (typeof(this._pageTracker) == 'string') ? window[this._pageTracker] : this._pageTracker;
	},
	
	/**
	 * Executa um "_trackPageview"
	 * @param {string} str String da marcação desejada
	 */
	track: function(str) {
		this.getTracker()._trackPageview(str);
	},
	
	/**
	 * Executa um "_trackPageview" e abre uma URL (window.open)
	 * @param {string} str String da marcação desejada
	 * @param {string} url desejada
	 * @param {string} target por padrão '_self'
	 */
	trackAndGo: function(str, url, target) {
		this.track(str);
		if(!target) target = '_self';
		if(!url) {
			throw new Error('[ERROR] Analytics.trackAndGo: undefined URL.');
		} else {
			setTimeout(function(){
				window.open(url, target);
			}, this._timeout);
		}
	},
	
	/**
	 * Executa um "_trackPageview" e após uma função JS (_timeout 250 milisegundos)
	 * @param {function} func Função javascript válida
	 * @param {string} str String da marcação desejada
	 */
	trackAndJs: function(str, func) {
		this.track(str);
		this.callJs(func);
	},
	
	/**
	 * Executa um "_trackEvent"
	 * @param {string} category String da categoria
	 * @param {string} action String da ação
	 * @param {string} optional_label String do label
	 * @param {number} optional_value
	 */
	trackEvent: function(category, action, optional_label, optional_value) {
		if(!category || !action) {
			throw new Error('[ERROR] Analytics.trackEvent: trackEvent must contain "category" and "action" parameters.');
		} else {
			if((optional_value && isNaN(optional_value)) || optional_value === true) {
				throw new Error('[ERROR] Analytics.trackEvent: optional_value must be a number.');
			} else {
				this.getTracker()._trackEvent(category, action, optional_label, optional_value);
			}
		}
	},
	
	/**
	 * Executa um "_trackEvent" e após uma função JS (_timeout 250 milisegundos)
	 * @param {function} func Função javascript válida
	 * @param {string} category String da categoria
	 * @param {string} action String da ação
	 * @param {string} optional_label String do label
	 * @param {number} optional_value
	 */
	trackEventAndJs: function(func, category, action, optional_label, optional_value) {
		this.trackEvent(category, action, optional_label, optional_value);
		this.callJs(func);
	},

	/**
	 * Executa uma função JS (_timeout 250 milisegundos)
	 * @param {function} func Função javascript válida
	 */
	callJs: function(func) {
		setTimeout(function() {
			try {
				func();
			} catch(e) {
				throw new Error('[ERROR] Analytics.callJs: undefined function called.');
			}
		}, this._timeout);
	},
	
	/**
	 * Executa um "_setVar"
	 * @param {string} str String da marcação desejada
	 */
	setVar: function(str) {
		this.getTracker()._setVar(str);
	}
}; 

//teste charCounter
/* function txtCounter(f,c,m){
	var f = $('#'+f);
	var c = $('#'+c);
	
	if (f.val().length > m)
		f.val(f.val().substring(0, m));
	else
		c.text(m - f.val().length);
}; */


//Somente Num ou Letra ;

(function($) {
	$.fn.only = function(type){
		this.each(function(){
			$(this).keypress(function(e){
				var key = 0, letter = '', pattern = '';
				
				if(window.event){
					key = window.event.keyCode;
				}else if(e){
					key = e.which;
				}else{
					return true;
				}
				
				letter = String.fromCharCode(key);
				
				switch (type) {
					case 'num':
					case 'number':
					case 'numeric':
						pattern = /\d/i;
						break;
						
					case 'let':
					case 'letters':
						pattern = /\D/i;
						break;
						
					case 'alnum':
					case 'alphanumeric':
						pattern = /\w/i;
						break;
						
					case 'low':
					case 'lower':
					case 'lowercase':
						pattern = /[a-z]/;
						break;
						
					case 'up':
					case 'upper':
					case 'uppercase':
						pattern = /[A-Z]/;
						break;
						
					case 'rest':
					case 'restrict':
						pattern = /[a-z0-9]/i;
						break;
						
					case 'email':
						pattern = /[a-z0-9@-_.]/i;
						break;
						
					default:
						pattern = /.*/i;
				}
				
				if (key === null || key === 0 || key === 8 || key === 9 || key === 13 || key === 27) {
					return true;
				}
				
				return pattern.test(letter);
			});
		});
		return this;
	};
})(jQuery);
/**
 * @author	Nicholas Almeida
 * @version	2.1.1
 * @original http://www.javascript-coder.com
*/

var valColorError = "#fbf9e7";
(function(scope){
	var __buttonSubmit__;
	var __newWidth__;
	var __buttonSubmitSrc__;
	var __cAlert__;
	var __lang__;
	var __cAlertDiv__;
	var __cAlertTxt__;
	var __oldFocus__;
	var __cAlertShow__ = true;

	scope.frmValidator = function(frmname, lang){
		this.formobj = $(frmname)[0];
		if(!this.formobj){
			alert('BUG: Não foi possívem acessar o formulário: '+frmname);
			return;
		};
		if(this.formobj.onsubmit){
			this.formobj.old_onsubmit = this.formobj.onsubmit;
			this.formobj.onsubmit=null;
		}else{
			this.formobj.old_onsubmit = null;
		};
		this.formobj.onsubmit=form_submit_handler;
		this.lang = __lang__ = lang;
		this.cAlert = customAlert;
		this.av = add_validation;
		this.cSubmit = change_submit;	
		this.amv = addMultiVal;
		this.customValidation=set_addnl_vfunction;
		this.clearAllValidations = clear_all_validations;
		this.formobj.onreset = rABgColor;
	};
	function set_addnl_vfunction(functionname){
		this.formobj.addnlvalidation = functionname;
	};
	function clear_all_validations(){
		for(var itr=0;itr < this.formobj.elements.length;itr++){
			this.formobj.elements[itr].validationset = null;
		};
	};
	function customAlert(d,t,s){
		if(!$(d)[0] || !$(t)[0]) {
			alert('BUG: Box id not defined or Text id not defined.');
			return;
		} else {
			__cAlert__ = true;
			__cAlertDiv__ = d;
			__cAlertTxt__ = t;
			__cAlertShow__ = s;		
		}
	};
	function form_submit_handler(){
		for(var itr=0;itr < this.elements.length;itr++){
			if(this.elements[itr].validationset && !this.elements[itr].validationset.validate()){
				return false;
			};
		};
		if(this.addnlvalidation){
			str =' var ret = '+this.addnlvalidation+'()';
			eval(str);
			if(!ret) return ret;
		};

		if(__buttonSubmit__){
			if (__lang__ == 'en'){
				stButton = 'Sending...'; 
			}else if(__lang__ == 'es'){
				stButton = 'Enviando...'; 
			}else{
				stButton = 'Enviando...'; 
			}

			__buttonSubmit__.title = stButton;
			if(__buttonSubmitSrc__){
				__buttonSubmit__.src = __buttonSubmitSrc__;
			}else{
				__buttonSubmit__.value = stButton;
			}
			__buttonSubmit__.disabled = 'disabled';
			__buttonSubmit__.style.cursor = 'wait';
			if(__newWidth__) {__buttonSubmit__.style.width = __newWidth__};
		}
		return true;
	};
	function add_validation(itemname,descriptor,errstr){
		if(!this.formobj){
			alert('BUG: Formulário não definido corretamente!');
			return;
		};
		var itemobj = this.formobj[itemname];
		if (!itemobj) alert('BUG: Não foi possível encontrar nehum campo com o name=' + itemname);
		if(itemobj.length && isNaN(itemobj.selectedIndex) ){
			itemobj = itemobj[0];
		};	
		if(!itemobj){
			alert('BUG: Não foi possível encontrar o campo com o nome: '+itemname);
			return;
		};

		if(!itemobj.validationset){
			itemobj.validationset = new ValidationSet(itemobj);
		};
		itemobj.validationset.add(descriptor,errstr);
	};
	function change_submit(bt,newWidth, buttonSubmitSrc){
		if(!this.formobj){
			alert('BUG: Formulário não definido corretamente!');
			return;
		};
		__buttonSubmit__ = $(bt)[0];
		__newWidth__ = newWidth;
		__buttonSubmitSrc__ = buttonSubmitSrc;
	};
	function ValidationDesc(inputitem,desc,error){
		this.desc=desc;
		this.error=error;
		this.itemobj = inputitem;
		this.validate=vdesc_validate;
	};
	function vdesc_validate() {
		if(!validateInput(this.desc,this.itemobj,this.error)){
			if(!__cAlert__) this.itemobj.focus();
			return false;
		};
		return true;
	};
	function ValidationSet(inputitem){
		this.vSet=new Array();
		this.add= add_validationdesc;
		this.validate= vset_validate;
		this.itemobj = inputitem;
	};
	function add_validationdesc(desc,error){
		this.vSet[this.vSet.length]= 
		new ValidationDesc(this.itemobj,desc,error);
	};
	function vset_validate(){
		for(var itr=0;itr<this.vSet.length;itr++){
			if(!this.vSet[itr].validate()){
				return false;
			};
		};
		return true;
	};
	function validateEmail(email){
		if (email.length <= 0) {
			return true;
		};
		var splitted = email.match('^(.+)@(.+)$');
		if (splitted == null)return false;
		if (splitted[1] != null ) {
			var regexp_user = /^\"?[\w-_\.]*\"?$/;
			if (splitted[1].match(regexp_user) == null)return false;
		};
		if (splitted[2] != null) {
			var regexp_domain = /^[\w-\.]*\.[A-Za-z]{2,4}$/;
			if (splitted[2].match(regexp_domain) == null) {
				var regexp_ip = /^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
				if (splitted[2].match(regexp_ip) == null)return false;
			};
			return true;
		};
		return false;
	};

	function TestComparison(objValue,strCompareElement,strvalidator,strError){
		var bRet=true;
		var objCompare=null;
		if(!objValue.form){
			alert('BUG: Formulário não definido!');
			return false
		};
		objCompare = objValue.form.elements[strCompareElement];
		if(!objCompare){
			alert('BUG: Campo com o nome '+strCompareElement+' não encontrado!');
			return false;
		};
		var cmpstr='';
		switch(strvalidator){
			case 'equal': 
			case 'eq': {
				if(objValue.value != objCompare.value){
					if (__lang__ == 'en'){
						cmpstr = ' must be the same as field \"';
					}else if(__lang__ == 'es'){
						cmpstr = ' debe ser igual al campo \"';
					}else{
						cmpstr = ' deve ser igual ao campo \"';
					}
					bRet = false;
				};
				break;
			};
			case 'notequal':
			case 'noteq': {
				if(objValue.value.length > 0 && objCompare.value.length > 0 && objValue.value == objCompare.value){
					if (__lang__ == 'en'){
						cmpstr = ' must be different from field \"';
					}else if(__lang__ == 'es'){
						cmpstr = ' debe ser diferente del campo \"';
					}else{
						cmpstr = ' deve ser diferente do campo \"';
					}
					bRet = false;
				};
				break;			
			};			
		};
		if(bRet==false){
			if(!strError || strError.length==0){
				if (__lang__ == 'en'){
					strError = 'Field \"' + objValue.title + '\"' + cmpstr + objCompare.title + '\".'; 
				}else if(__lang__ == 'es'){
					strError = 'El campo \"' + objValue.title + '\"' + cmpstr + objCompare.title + '\".'; 
				}else{
					strError = 'O campo \"' + objValue.title + '\"' + cmpstr + objCompare.title + '\".'; 
				}
				cBgColor(objValue);
			};
			boxAlert(strError, objValue);
		};
		if(bRet) rBgColor(objValue);
		return bRet;
	};

	function TestSelMin(objValue,strMinSel,strError){
		var bret = true;
		var objcheck = objValue.form.elements[objValue.name];
		var chkcount =0;
		if(objcheck.length){
			for(var c=0;c < objcheck.length;c++){
				if(objcheck[c].checked == '1'){
					chkcount++;
				};
			};
		}else {
			chkcount = (objcheck.checked == '1')?1:0;
		};
		var minsel = eval(strMinSel);
		if(chkcount < minsel) {
			if(!strError || strError.length ==0) { 
				if (__lang__ == 'en'){
					strError = 'Select at least ' + minsel + ' option(s) for field \"' + objValue.title + '\".';
				}else if(__lang__ == 'es'){
					strError = 'Seleccione al menos ' + minsel + ' opciones para el campo \"' + objValue.title + '\".';
				}else{
					strError = 'Selecione ao menos ' + minsel + ' opção(ões) para o campo \"' + objValue.title + '\".';
				}
			};
			boxAlert(strError, objValue); 
			bret = false;
		};
		if(bret) rBgColor(objValue);
		return bret;
	};

	function TestSelMax(objValue,strMaxSel,strError){
		var gret = true;
		var objcheck = objValue.form.elements[objValue.name];
		var chkcount =0;
		if(objcheck.length){
			for(var c=0;c < objcheck.length;c++){
				if(objcheck[c].checked == '1'){
					chkcount++;
				};
			};
		}else {
			chkcount = (objcheck.checked == '1')?1:0;
		};
		var maxsel = eval(strMaxSel);
		if(chkcount > maxsel) {
			if(!strError || strError.length ==0) { 
				if (__lang__ == 'en'){
					strError = 'Select at the most ' + maxsel + ' option(s) for field \"' + objValue.title + '\".';
				}else if(__lang__ == 'es'){
					strError = 'Seleccione como máximo ' + maxsel + ' opciones para el campo \"' + objValue.title + '\".';
				}else{
					strError = 'Selecione no máximo ' + maxsel + ' opção(ões) para o campo \"' + objValue.title + '\".';
				}
			};
			boxAlert(strError, objValue); 
			gret = false;
		};
		if(gret) rBgColor(objValue);
		return gret;
	};

	function TestDontSelect(objValue,index,strError){
		var ret = true;
		if(objValue.selectedIndex == null) { 
			alert('BUG: Este comando só pode ser usado para elementos de seleção.'); 
			ret = false; 
		}else if(objValue.selectedIndex == eval(index)) { 
			if(!strError || strError.length ==0) { 
				if (__lang__ == 'en'){
					strError = 'Select one of the options for field \"' + objValue.title + '\".'; 
				}else if(__lang__ == 'es'){
					strError = 'Seleccione una de las opciones para el campo \"' + objValue.title + '\".'; 
				}else{
					strError = 'Selecione uma das opções para o campo \"' + objValue.title + '\".'; 
				}
			};                                                        
			boxAlert(strError, objValue); 
			ret =  false;
			cBgColor(objValue);                            
		}; 
		if(ret) rBgColor(objValue);
		return ret;
	};

	function TestRequiredInput(objValue,strError){
		var ret = true;
		if(eval(objValue.value.length) == 0) { 
			if(!strError || strError.length ==0) { 
				if (__lang__ == 'en'){
					strError = 'Field \"' + objValue.title + '\" must be filled out.'; 
				}else if(__lang__ == 'es'){
					strError = 'El campo \"' + objValue.title + '\" es obligatorio.'; 
				}else{
					strError = 'O campo \"' + objValue.title + '\" é obrigatório.'; 			
				}
			};
			boxAlert(strError, objValue);
			ret=false; 
			cBgColor(objValue);
		};
		if(ret) rBgColor(objValue);
		return ret;
	};

	function TestMaxLen(objValue,strMaxLen,strError){
		var ret = true;
		if(eval(objValue.value.length) > eval(strMaxLen)) { 
			if(!strError || strError.length ==0) {
				if (__lang__ == 'en'){
					strError = 'Field \"' + objValue.title + '\" can contain up to '+ strMaxLen +' character(s).'; 
					strErrorCont = 'Currently it has: ' + objValue.value.length + ' character(s).';
				}else if(__lang__ == 'es'){
					strError = 'El campo \"' + objValue.title + '\" puede contener hasta '+ strMaxLen +' caracter(es).'; 
					strErrorCont = 'Actualmente tiene: ' + objValue.value.length + ' carácter(es).';
				}else{
					strError = 'O campo \"' + objValue.title + '\" pode conter no máximo '+ strMaxLen +' caracter(es).'; 
					strErrorCont = 'Atualmente ele tem: ' + objValue.value.length + ' caracter(es).';
				}
			};
			cBgColor(objValue);
			boxAlert(strError + '\n' + strErrorCont, objValue); 
			ret = false; 
		};
		if(ret) rBgColor(objValue);
		return ret;
	};

	function TestMinLen(objValue,strMinLen,strError){
		var ret = true;
		if(eval(objValue.value.length) <  eval(strMinLen)) { 
			if(!strError || strError.length ==0) { 
				if (__lang__ == 'en'){
					strError = 'Field \"' + objValue.title + '\" must contain at least '+ strMinLen +' character(s).'; 
					strErrorCont = 'Currently it has: ' + objValue.value.length + ' character(s).';
				}else if(__lang__ == 'es'){
					strError = 'El campo \"' + objValue.title + '\" debe contener un mínimo de '+ strMinLen +' caracter(es).'; 
					strErrorCont = 'Actualmente tiene: ' + objValue.value.length + ' carácter(es).';
				}else{
					strError = 'O campo \"' + objValue.title + '\" deve conter no mínimo ' + strMinLen + ' caracter(es).'; 
					strErrorCont = 'Atualmente ele tem: ' + objValue.value.length + ' caracter(es).';
				}
			};
			cBgColor(objValue);
			boxAlert(strError + '\n' + strErrorCont, objValue); 
			ret = false;   
		};
		if(ret) rBgColor(objValue);
		return ret;
	};

	function TestInputType(objValue,strRegExp,strError,strDefaultError){
		var ret = true;
		var charpos = objValue.value.search(strRegExp); 
		if(objValue.value.length > 0 &&  charpos >= 0) { 
			if(!strError || strError.length ==0) { 
				strError = strDefaultError;
				if (__lang__ == 'en'){
					strErrorCont = 'Error of character in position: ';
				}else if(__lang__ == 'es'){
					strErrorCont = 'Error en el carácter en la posición: ';
				}else{
					strErrorCont = 'Erro no caracter na posição: ';
				}
			};
			cBgColor(objValue);
			boxAlert(strError + '\n' + strErrorCont + eval(charpos+1)+'.', objValue); 
			ret = false; 
		};
		if(ret) rBgColor(objValue);
		return ret;
	};

	function TestEmail(objValue,strError){
		var ret = true;
		if(objValue.value.length > 0 && !validateEmail(objValue.value)	 ) { 
			if(!strError || strError.length ==0) { 
				if (__lang__ == 'en'){
					strError = '\"' + objValue.value+'\" is not a valid e-mail for field \"' + objValue.title + '\".'; 
				}else if(__lang__ == 'es'){
					strError = '\"' + objValue.value+'\" no es un e-mail válido para el campo \"' + objValue.title + '\".'; 
				}else{
					strError = '\"' + objValue.value+'\" não é um e-mail válido para o campo \"' + objValue.title + '\".'; 
				}
			};
			boxAlert(strError, objValue); 
			ret = false; 
			cBgColor(objValue);
		};
		if(ret) rBgColor(objValue);
		return ret;
	};

	function TestRegExp(objValue,strRegExp,strError){
		var ret = true;
		if( objValue.value.length > 0 && !objValue.value.match(strRegExp) ) { 
			if(!strError || strError.length ==0) {
				if (__lang__ == 'en'){
					strError = 'Invalid character found in field \"' + objValue.title + '\".';
				}else if(__lang__ == 'es'){
					strError = 'Carácter no permitido encontrado en el campo \"' + objValue.title + '\".';
				}else{
					strError = 'Caracter não permitido encontrado no campo \"' + objValue.title + '\".';
				}
			};
			boxAlert(strError, objValue); 
			ret = false;
			cBgColor(objValue);
		};
		if(ret) rBgColor(objValue);
		return ret;
	};

	function TestSelectOneRadio(objValue,strError){
		var objradio = objValue.form.elements[objValue.name];
		if (!objradio) alert('BUG: Não foi possível encotrar nenhum radioButton no formulário.\nCertifique-se de que eles existem e que tem o atributo \"name\".');
		var one_selected=false;
		for(var r=0;r < objradio.length;r++){
			if(objradio[r].checked == '1'){
				one_selected=true;
				break;
			};
		};
		if(false == one_selected){
			if(!strError || strError.length ==0) {
				if (__lang__ == 'en'){
					strError = 'Select one of the options for field  \"'+objValue.title+'\".'; 
				}else if(__lang__ == 'es'){
					strError = 'Seleccione una de las opciones para el campo \"'+objValue.title+'\".'; 
				}else{
					strError = 'Selecione uma das opções para o campo \"'+objValue.title+'\".'; 
				}
			};	
			boxAlert(strError, objValue);
		};
		return one_selected;
	};

	function TestCpf(v) {
		if (v == "00000000000" || v == "11111111111" || v == "22222222222" || v == "33333333333" || v == "44444444444" || v == "55555555555" || v == "66666666666" || v == "77777777777" || v == "88888888888" || v == "99999999999") return false;
		if(!v) return true;
		var s=null;
		var r=null;
		if(v.length!=11||v.match(/1{11};|2{11};|3{11};|4{11};|5{11};|6{11};|7{11};|8{11};|9{11};|0{11};/)) return false;
		s=0;
		for(var i=0;i<9;i++) s+=parseInt(v.charAt(i))*(10-i);
		r=11-(s%11);
		if(r==10||r==11) r=0;
		if(r!=parseInt(v.charAt(9))) return false;
		s=0;
		for(var i=0;i<10;i++) s+=parseInt(v.charAt(i))*(11-i);
		r=11-(s%11);
		if(r==10||r==11) r=0;
		if(r!=parseInt(v.charAt(10))) return false;
		return true;
	};

	function TestCnpj(v) {
		if(!v) return true;
		var m = new Array('543298765432','6543298765432');
		var d = new Array(0,0);
		for (var t=0; t<2; t++) {
			for(x=0; x<13; x++) {
				if ((t==0 && x!=12) || t==1) d[t] += ( parseInt(v.slice(x,x+1)) * parseInt(m[t].slice(x,x+1)) );
			};
			d[t] = (d[t] * 10) % 11;
			if (d[t] == 10) d[t] = 0;
		};
		return (d[0] == parseInt(v.slice(12,13)) && d[1] == parseInt(v.slice(13,14)));
	};

	function TestFile(v ,ext) {
		if(!v) return true;
		var e = ext.split(",");
		for(var i=0; i<e.length; i++) {
			if (v.substr(v.lastIndexOf('.')+1)==e[i]) return true;
		};
		return false;
	};

	function replaceAll(str, replacements ) {
		for ( i = 0; i < replacements.length; i++ ) {
			var idx = str.indexOf( replacements[i][0] );
			while ( idx > -1 ) {
				str = str.replace( replacements[i][0], replacements[i][1] );
				idx = str.indexOf( replacements[i][0] );
			};
		};
		return str;
	};
	function addMultiVal(){
		var arrPar = [];
		for(var i=0; i<arguments.length; i++){
			arrPar[i] = arguments[i];
		};
		var fld = arrPar[0];
		arrPar = arrPar.slice(1,arrPar.length);
		for (var a=0;a<arrPar.length;a++){
			this.av(fld,arrPar[a]);
		};
		delete arrPar, fld;
	};
	function validateInput(strValidateStr,objValue,strError) {
		var ret = true;
		var epos = strValidateStr.search('='); 
		var command  = ''; 
		var cmdvalue = ''; 
		if(epos >= 0) { 
			command  = strValidateStr.substring(0,epos); 
			cmdvalue = strValidateStr.substr(epos+1); 
		}else { 
			command = strValidateStr; 
		}; 
		switch(command) { 
			case 'req': 
			case 'required': { 
				ret = TestRequiredInput(objValue,strError);
				break;             
			};
			case 'maxlength': 
			case 'maxlen': { 
				ret = TestMaxLen(objValue,cmdvalue,strError);
				break; 
			};
			case 'minlength': 
			case 'minlen': { 
				ret = TestMinLen(objValue,cmdvalue,strError);
				break; 
			};
			case 'alnum': 
			case 'alphanumeric': { 
				if (__lang__ == 'en'){
					strTxtError = 'Only alphanumeric characters (letters and numbers) are valid for field'; 
				}else if(__lang__ == 'es'){
					strTxtError = 'Sólo caracteres alfanuméricos (letras y números) son permitidos para el campo'; 
				}else{
					strTxtError = 'Apenas caracteres alfanuméricos(letras e números) são permitidos para o campo';
				}
			
				ret = TestInputType(objValue,'[^A-Za-z0-9áàãâäéèêëíìîïóòõôöúùûüçÁÀÃÂÄÉÈÊËÍÌÎÏÓÒÕÔÖÚÙÛÜÇ\\s]',strError, strTxtError + ' \"' + objValue.title + '\".');
				break;
			};
			case 'num': 
			case 'number': 
			case 'numeric': {
				if (__lang__ == 'en'){
					strTxtError = 'Only numeric characters (numbers) are valid for field'; 
				}else if(__lang__ == 'es'){
					strTxtError = 'Sólo caracteres numéricos (números) son permitidos para el campo'; 
				}else{
					strTxtError = 'Apenas caracteres numéricos(números) são permitidos para o campo';
				}
			 
				ret = TestInputType(objValue,'[^0-9]',strError,  strTxtError + ' \"' + objValue.title + '\".');
				break;
			};
			case 'letters': 
			case 'let': { 
				if (__lang__ == 'en'){
					strTxtError = 'Only letters are valid for field'; 
				}else if(__lang__ == 'es'){
					strTxtError = 'Sólo letras son permitidas para el campo'; 
				}else{
					strTxtError = 'Apenas letras são permitidas para o campo';
				}
			
				ret = TestInputType(objValue,'[^A-Za-záàãâäéèêëíìîïóòõôöúùûüçÁÀÃÂÄÉÈÊËÍÌÎÏÓÒÕÔÖÚÙÛÜÇ\\s]',strError, strTxtError + ' \"' + objValue.title + '\".');
				break; 
			};
			case 'restrict':
			case 'rest': { 
				if (__lang__ == 'en'){
					strTxtError = 'Only letters, numbers, \"-\" and \"_\" are valid for field'; 
				}else if(__lang__ == 'es'){
					strTxtError = 'Sólo letras, números, \"-\" y \"_\" son permitidos para el campo'; 
				}else{
					strTxtError = 'Apenas letras, números, \"-\" e \"_\"  são permitidas para o campo';
				}
				ret = TestInputType(objValue,'[^A-Za-z0-9-_]',strError, strTxtError + ' \"' + objValue.title + '\".');
				break; 
			};
			case 'email': { 
				ret = TestEmail(objValue,strError);
				break; 
			};
			case "lt":
			case "lessthan":{
				if (isNaN(objValue.value)) {
					if (__lang__ == 'en'){
						strTxtError = 'Only numeric characters (numbers) are valid for field'; 
					}else if(__lang__ == 'es'){
						strTxtError = 'Sólo caracteres numéricos (números) son permitidos para el campo'; 
					}else{
						strTxtError = 'Apenas caracteres numéricos(números) são permitidos para o campo';
					}
						
					boxAlert(strTxtError + ' \"' + objValue.title + '\".', objValue);
					cBgColor(objValue);
					return false;
				};
				if (eval(objValue.value) > eval(cmdvalue)) {
					if (!strError || strError.length == 0) {
						if (__lang__ == 'en'){
							strError = 'Field \"' + objValue.title + '\" must be smaller or equal than: ' + cmdvalue + '.';
						}else if(__lang__ == 'es'){
							strError = 'El campo \"' + objValue.title + '\" debe ser menor o igual a: ' + cmdvalue + '.';
						}else{
							strError = 'O campo \"' + objValue.title + '\" deve ser menor ou igual a: ' + cmdvalue + '.';
						}
					};
					boxAlert(strError, objValue);
					cBgColor(objValue);
					return false;
				};
				break;
			};
			case "gt":
			case "greaterthan":{
				if (isNaN(objValue.value)) {
					if (__lang__ == 'en'){
						strTxtError = 'Only numeric characters (numbers) are valid for field'; 
					}else if(__lang__ == 'es'){
						strTxtError = 'Sólo caracteres numéricos (números) son permitidos para el campo'; 
					}else{
						strTxtError = 'Apenas caracteres numéricos(números) são permitidos para o campo';
					}
					boxAlert(strTxtError + ' \"' + objValue.title + '\".', objValue);
					cBgColor(objValue);
					return false;
				};
				if (eval(objValue.value) < eval(cmdvalue)) {
					if (!strError || strError.length == 0) {
						if (__lang__ == 'en'){
							strError = 'Field \"' + objValue.title + '\" must be bigger or equal than: ' + cmdvalue + '.';
						}else if(__lang__ == 'es'){
							strError = 'El campo \"' + objValue.title + '\" debe ser mayor o igual a: ' + cmdvalue + '.';
						}else{
							strError = 'O campo \"' + objValue.title + '\" deve ser maior ou igual a: ' + cmdvalue + '.';
						}
					};
					boxAlert(strError, objValue);
					cBgColor(objValue);
					return false;
				};
				break;
			};
			case 'regex': { 
				ret = TestRegExp(objValue,cmdvalue,strError);
				break; 
			};
			case 'dontselect': { 
				ret = TestDontSelect(objValue,cmdvalue,strError);
				break; 
			};
			case 'selmin':{
				ret = TestSelMin(objValue,cmdvalue,strError);
				break;
			};
			case 'selmax':{
				ret = TestSelMax(objValue,cmdvalue,strError);
				break;
			};
			case 'selone':{
				ret = TestSelectOneRadio(objValue,strError);
				break;
			};		 
			case 'equal': 
			case 'eq': 
			case 'notequal':
			case 'noteq':{
				return TestComparison(objValue,cmdvalue,command,strError);
				break;
			};
			case 'cpf': { 
				var tmpValue = replaceAll(objValue.value, [['.', ''],[ '/', '' ],['-', ''],[' ', '']]);
				ret = TestCpf(tmpValue);
				if(!ret) {
						if (__lang__ == 'en'){
							strErrorTxt = 'is not a valid CPF number for field';
						}else if(__lang__ == 'es'){
							strErrorTxt = 'no es un número de CPF válido para el campo';
						}else{
							strErrorTxt = 'não é um número de CPF válido para o campo';
						}
							
					boxAlert('\"' + objValue.value + '\" ' + strErrorTxt + ' \"' + objValue.title + '\".', objValue);
					cBgColor(objValue);
				}
				else rBgColor(objValue);
				delete tmpValue;
				break;             
			};
			case 'cnpj': { 
				var tmpValue = replaceAll(objValue.value, [['.', ''],[ '/', '' ],['-', ''],[' ', '']]);
				ret = TestCnpj(tmpValue);
				if(!ret) {
					if (__lang__ == 'en'){
						strErrorTxt = 'is not a valid CNPJ number for field';
					}else if(__lang__ == 'es'){
						strErrorTxt = 'no es un número de CNPJ válido para el campo';
					}else{
						strErrorTxt = 'não é um número de CNPJ válido para o campo';
					}
							
					boxAlert('\"' + objValue.value + '\" ' + strErrorTxt + ' \"' + objValue.title + '\".', objValue);
					cBgColor(objValue);
				}
				else rBgColor(objValue);
				delete tmpValue;
				break;             
			};
			case 'file': { 
				ret = TestFile(objValue.value.toLowerCase(), cmdvalue);
				if(!ret) {
					if (__lang__ == 'en'){
						boxAlert('Field \"' + objValue.title + '\" allows only \".' + cmdvalue +' \"archives.', objValue);
					}else if(__lang__ == 'es'){
						boxAlert('El campo \"' + objValue.title + '\" permite sólo archivos con la extensión \".' + cmdvalue +' \".', objValue);
					}else{
						boxAlert('O campo \"' + objValue.title + '\" permite somente arquivos com a extensão \".' + cmdvalue +' \".', objValue);
					}
					cBgColor(objValue);
				}
				else rBgColor(objValue);
				delete tmpValue;
				break;             
			};
		};
		if(ret) rBgColor(objValue);
		return ret; 
	};

	function cBgColor(o){o.style.backgroundColor = valColorError;};

	function rBgColor(o){o.style.backgroundColor = "";};

	function rABgColor(){
		for (var itr = 0; itr < this.elements.length; itr++) {
			rBgColor(this.elements[itr]);
		};
	};

	function only(t,o,e) {
		if(window.event)key=window.event.keyCode;
		else if(e)key=e.which;
		else return true;
		S=(o)?o:'';
		if(t=='num'||t=='number'||t=='numeric')S+='0123456789';
		if(t=='alnum'||t=='alphanumeric')S+='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZáàãâäéèêëíìîïóòõôöúùûüçÁÀÃÂÄÉÈÊËÍÌÎÏÓÒÕÔÖÚÙÛÜÇ 0123456789';
		if(t=='let'||t=='letters')S+='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZáàãâäéèêëíìîïóòõôöúùûüçÁÀÃÂÄÉÈÊËÍÌÎÏÓÒÕÔÖÚÙÛÜÇ ';	
		if(t=='rest'||t=='restrict')S+='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
		if(t=='email')S+='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@-_.';
		if(key==null||key==0||key==8||key==9||key==13||key==27)return true;
		else if(S.indexOf(String.fromCharCode(key))!=-1)return true;
		else return false;
	};

	function not(S,e) {
		if(window.event)key=window.event.keyCode;
		else if(e)key=e.which;
		else return true;
		if(!S)return false;
		else if(key==null||key==0||key==8||key==9||key==13||key==27)return true;
		else if(S.indexOf(String.fromCharCode(key))!=-1)return false;
		else return true;
	};


	function jump(o,e) {
		if(window.event)key=window.event.keyCode;
		else if(e)key=e.which;
		else return;
		if (key==9||key==2||key==16) return;
		if(o.value.length==o.maxLength){
			for(var i=0;i<o.form.length;i++){
				if(o.form[i]==o&&o.form[i+1]){
					if(o.form[i+1]) o.form[i+1].focus();
					break;
				};
			}
		};
	};

	function checkReset(f){
		if (__lang__ == 'en'){
			strErrorTxt = 'All data submitted will be deleted.\nTo delete all data click \"OK\".\nTo continue submitting information click \"Cancel\".';
		}else if(__lang__ == 'es'){
			strErrorTxt = 'Todos los datos registrados serán borrados.\nPara borrar todos los datos haga clic en \"OK\".\nPara continuar registrando haga clic en \"Cancelar\".';
		}else{
			strErrorTxt = 'Todos os dados preenchidos serão apagados.\nPara apagar todos os dados clique em \"OK\".\nPara continuar preenchendo clique em \"Cancelar\".';
		}
		if(confirm(strErrorTxt)) $(f)[0].reset();
	};

	function clearMe(w,s){
		(w.value == s) ? w.value='' : 0;
	};

	function leaveMe(w,s){
		(w.value.length == 0) ? w.value = s : 0;
	};

	function boxAlert(x, f){
		if(__cAlert__) {
			if(__cAlertShow__){
				openBox(__cAlertDiv__);
			}  else {
				$(__cAlertDiv__).show();
			}
			$(__cAlertTxt__)[0].innerHTML = x;
			__oldFocus__ = f;
			
		} else {
			alert(x); 
		}
		$('input', f.form).blur();
	};

	function oldFocus(){
		__oldFocus__.focus();
	};
})(this);
